import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'EndGame.dart';
import 'PauseMenu.dart';
import 'mygame.dart';


class TJGame extends StatelessWidget {
  const TJGame({Key? key}) : super(key: key);

  // This widget is the root of your application.
  final TextStyle stryle = const TextStyle(
      color: Colors.purple,
      fontSize: 30,
      shadows: [Shadow(color: Colors.white, blurRadius: 10)]);
  void _goToGame(BuildContext context) {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => GameWorld()),
    );
  }

  void _showDialog(BuildContext context) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          content: Container(
            width: MediaQuery.of(context).size.width / 2,
            height: MediaQuery.of(context).size.height / 2,
            child: Center(
              child: GameWorld()
            ),
          ),
          // actions: [
          //   ElevatedButton(
          //     onPressed: () {
          //       Navigator.of(context).pop();
          //     },
          //     child: Text('Close'),
          //   ),
          // ],
        );
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      children: [
        Divider(),
        Center(
            child: Wrap(
          spacing: 20,
          direction: Axis.vertical,
          crossAxisAlignment: WrapCrossAlignment.center,
          children: [
            Text('Man Game by TuJun', style: stryle),
            ElevatedButton(
              onPressed: () => _showDialog(context),
              child: const Text('开始游戏'),
            ),
            ElevatedButton(
                onPressed: () {
                  Navigator.of(context).pop();
                },
                child: const Text('退出游戏')),
          ],
        )),
      ],
    ));
  }
}

class GameWorld extends StatelessWidget {
  const GameWorld({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    //全屏
    return GameWidget<MyGame>(
      game: MyGame(),
      overlayBuilderMap: {
        PauseMenu.menuId: (context, game) => PauseMenu(game: game),
        EndGame.menuId: (context, game) => EndGame(game: game),
      },
    );
    // 窗口
    // return Stack(
    //   children: [
    //     Positioned(
    //         bottom: 0,
    //         left: 0,
    //         right: 0,
    //         height: MediaQuery.of(context).size.height / 2,
    //         child: GameWidget<MyGame>(
    //           game: MyGame(),
    //           overlayBuilderMap: {
    //             PauseMenu.menuId: (context, game) => PauseMenu(game: game),
    //             EndGame.menuId: (context, game) => EndGame(game: game),
    //           },
    //         )),
    //     SizedBox(height: 16),
    //   ],
    // );
  }
}
